var e = require("../../../../../@babel/runtime/helpers/objectSpread2"), t = require("../../../../../@babel/runtime/helpers/typeof"), r = require("../../../../../common/vendor.js"), a = require("../helpers/buildURL.js"), i = require("../core/buildFullPath.js"), l = require("../core/settle.js"), n = require("../utils.js"), o = function(e, t) {
    var r = {};
    return e.forEach(function(e) {
        n.isUndefined(t[e]) || (r[e] = t[e]);
    }), r;
};

exports.adapter = function(n) {
    return new Promise(function(d, u) {
        var s, c = a.buildURL(i.buildFullPath(n.baseURL, n.url), n.params, n.paramsSerializer), h = {
            url: c,
            header: n.header,
            complete: function(e) {
                n.fullPath = c, e.config = n, e.rawData = e.data;
                try {
                    var r = !1, a = t(n.forcedJSONParsing);
                    "boolean" === a ? r = n.forcedJSONParsing : "object" === a && (r = (n.forcedJSONParsing.include || []).includes(n.method)), 
                    r && "string" == typeof e.data && (e.data = JSON.parse(e.data));
                } catch (e) {}
                l.settle(d, u, e);
            }
        };
        if ("UPLOAD" === n.method) {
            delete h.header["content-type"], delete h.header["Content-Type"];
            var f = {
                filePath: n.filePath,
                name: n.name
            };
            s = r.index.uploadFile(e(e(e({}, h), f), o([ "timeout", "formData" ], n)));
        } else if ("DOWNLOAD" === n.method) {
            s = r.index.downloadFile(e(e({}, h), o([ "timeout", "filePath" ], n)));
        } else {
            s = r.index.request(e(e({}, h), o([ "data", "method", "timeout", "dataType", "responseType", "enableHttp2", "enableQuic", "enableCache", "enableHttpDNS", "httpDNSServiceId", "enableChunked", "forceCellularNetwork" ], n)));
        }
        n.getTask && n.getTask(s, n);
    });
};